obtain(B,S,C,Zs):-B>S, S>=C, ob(B,0,S,0, C,[],[],As), reverse(As,Zs), write_term(Zs, [max_depth(100)]).

ob(_,_,_,C, C, _, Ls, Ls):-!.

ob(B,Rb,S, Rs, C, Lp, Ls, As):-controlla((Rb,Rs),Lp), Rb\=B, ob(B,Rb,S, S, C, [(Rb,Rs)|Lp], [fillSmall|Ls], As).
ob(B,Rb,S, Rs, C, Lp, Ls, As):-controlla((Rb,Rs),Lp), Rs\=S, ob(B,B,S, Rs, C, [(Rb,Rs)|Lp], [fillBig| Ls], As).

ob(B,Rb,S,Rs, C, Lp, Ls, As):-controlla((Rb,Rs),Lp), ob(B,Rb,S,0, C, [(Rb,Rs)|Lp], [pourSmall|Ls],As).
ob(B,Rb,S,Rs, C, Lp, Ls, As):-controlla((Rb,Rs),Lp), ob(B,0,S,Rs, C, [(Rb,Rs)|Lp], [pourBig|Ls],As).

ob(B,Rb,S,Rs, C, Lp, Ls, As):-controlla((Rb,Rs),Lp), SS is S-Rs, SS>0, Br is Rb-SS, Br >= 0, ob(B,Br,S,S,C, [(Rb,Rs)|Lp], [bigInSmall|Ls],As).
ob(B,Rb,S,Rs, C, Lp, Ls, As):-controlla((Rb,Rs),Lp), Rb =< S-Rs, Sum is Rs+Rb, ob(B, 0, S, Sum, C, [(Rb,Rs)|Lp], [bigInSmall|Ls], As).

ob(B,Rb,S,Rs, C, Lp, Ls, As):-controlla((Rb,Rs),Lp), BB is B-Rb, BB>0, Sr is Rs-BB, Sr >= 0, ob(B,B,S,Sr,C, [(Rb,Rs)|Lp], [smallInBig|Ls],As).
ob(B,Rb,S,Rs, C, Lp, Ls, As):-controlla((Rb,Rs),Lp), Rs =< B-Rb, Sum is Rs+Rb, ob(B, Sum, S, 0, C, [(Rb,Rs)|Lp], [smallInBig|Ls], As).

controlla(C,L):-not(member(C,L)).
